import Mock from "mockjs";

//延时200-600毫秒请求到数据
Mock.setup({
    // timeout: '300', // 延时300ms
    timeout: '600-1600'
})

const bannerOptions = {
    imgSize: "1000x400",
    bgColor:'@color',
    title:'@cword(4, 8)',
    subTitle:'@cword(6, 8)'
};
Mock.mock('/api/homepage', 'get', {
    status: 200,
    message: '添加成功',
    data: {
        nums:[1,2,3,4,5,6,7,8,9],
        hero:[
            {name:'@cword(4, 8)', 'id|+1': 0}
        ],
        banner: [
            {
                bgColor:bannerOptions.bgColor,
                imgSrc:Mock.Random.image(bannerOptions.imgSize,Mock.Random.color(), '#FFFFFF', 'png', bannerOptions.title),
                title:bannerOptions.title,
                subTitle:bannerOptions.subTitle
            },
            {
                bgColor:bannerOptions.bgColor,
                imgSrc:Mock.Random.image(bannerOptions.imgSize,Mock.Random.color(), '#FFFFFF', 'png', bannerOptions.title),
                title:bannerOptions.title,
                subTitle:bannerOptions.subTitle
            },
            {
                bgColor:bannerOptions.bgColor,
                imgSrc:Mock.Random.image(bannerOptions.imgSize,Mock.Random.color(), '#FFFFFF', 'png', bannerOptions.title),
                title:bannerOptions.title,
                subTitle:bannerOptions.subTitle
            },
            {
                bgColor:bannerOptions.bgColor,
                imgSrc:Mock.Random.image(bannerOptions.imgSize,Mock.Random.color(), '#FFFFFF', 'png', bannerOptions.title),
                title:bannerOptions.title,
                subTitle:bannerOptions.subTitle
            }
        ],
        sports: ()=>{
            const sports = [];
            for(let i=0;i<10;i++){
                sports.push({
                    name:Mock.Random.cname(),
                    imgSrc:Mock.Random.image('150x80',Mock.Random.color())
                });
            }
            return sports;
        }
    }
});
Mock.mock('/api/getProductList', 'get', {
    status: 200,
    message: '查询成功',
    data: ()=>{
        const products = [];
        const hdr = ['000', '001', '002', '003', '004', '005'];
        const modelNames = ['bag2.glb', 'Macbookpro.glb', 'shoes.glb', 'women.glb'];
        for(let i=0;i<4;i++){
            products.push({
                id:Mock.mock('@id'),
                uuid:Mock.mock('@id'),
                desc:[{title: Mock.mock('@csentence()'), content: Mock.mock('@csentence()')}, {title: Mock.mock('@csentence()'), content: Mock.mock('@csentence()')}, {title: Mock.mock('@csentence()'), content: Mock.mock('@csentence()')}, {title: Mock.mock('@csentence()'), content: Mock.mock('@csentence()')}],
                title:Mock.mock('@ctitle()'),
                imgSrc:Mock.Random.image('150x80',Mock.Random.color()),
                price:Mock.mock('@float(200, 800, 2, 2)'),
                modelName: modelNames[i]
            });
        }
        return {products, hdr};
    }
});

Mock.mock('/api/getprodlist', 'get', {
    status: 0,
    'message|2-10': [
        {
            'id|+1': 0,
            name: '@cword(4, 8)',
            ctime: new Date()
        }
    ]
});
Mock.mock('/api/addproduct', 'post', {
    status: 0,
    message: '添加成功'
});
Mock.mock(/\/api\/delproduct/, 'get', {
    status: 0,
    message: '删除品牌数据OK'
});
